import 'dart:math';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class InviteRecord {
  final String id;
  final String time;

  InviteRecord({required this.id, required this.time});
}

class InviteRecordController extends GetxController {
  // 生成假数据
  List<InviteRecord> items = List.generate(25, (index) {
    final random = Random();
    final randomId = String.fromCharCode(65 + random.nextInt(26)) + 
                    (10000 + random.nextInt(89999)).toString();
    
    final now = DateTime.now();
    final pastDate = now.subtract(Duration(minutes: index * 30)); 
    final time = "${pastDate.year}.${pastDate.month.toString().padLeft(2, '0')}.${pastDate.day.toString().padLeft(2, '0')} ${pastDate.hour.toString().padLeft(2, '0')}:${pastDate.minute.toString().padLeft(2, '0')}:00";
    
    return InviteRecord(
      id: "ID:$randomId",
      time: time,
    );
  });
  
  RefreshController refreshController =
      RefreshController(initialRefresh: false);

  void onRefresh() async{
    // monitor network fetch
    await Future.delayed(Duration(milliseconds: 1000));
    // if failed,use refreshFailed()
    refreshController.refreshCompleted();
  }

  void onLoading() async{
    // monitor network fetch
    await Future.delayed(Duration(milliseconds: 1000));
    // if failed,use loadFailed(),if no data return,use LoadNodata()
    // 添加更多假数据
    final random = Random();
    for (int i = 0; i < 5; i++) {
      final randomId = String.fromCharCode(65 + random.nextInt(26)) + 
                      (10000 + random.nextInt(89999)).toString();
      
      final now = DateTime.now();
      final pastDate = now.subtract(Duration(minutes: (items.length + i) * 30)); 
      final time = "${pastDate.year}.${pastDate.month.toString().padLeft(2, '0')}.${pastDate.day.toString().padLeft(2, '0')} ${pastDate.hour.toString().padLeft(2, '0')}:${pastDate.minute.toString().padLeft(2, '0')}:00";
      
      items.add(InviteRecord(
        id: "ID:$randomId",
        time: time,
      ));
    }
    refreshController.loadComplete();
  }
}